package com.hanbang.maige.pressenter.quanzi;

import android.support.design.widget.Snackbar;

import com.hanbang.maige.code.base.presenter.BasePresenter;
import com.hanbang.maige.mode.HttpRequest;
import com.hanbang.maige.mode.httpresponse.BaseHttpResponse;
import com.hanbang.maige.mode.javabean.quanzi.FaBuFriendData;
import com.hanbang.maige.utils.http.httpquest.HttpCallBack;
import com.hanbang.maige.utils.http.httpquest.HttpRequestParam;
import com.hanbang.maige.utils.ui.SnackbarUtil;
import com.hanbang.maige.view.quanzi.IQuanZiBaseView;

/**
 * 作者　　: 李坤
 * 创建时间:2016/9/19　17:05
 * 邮箱　　：496546144@qq.com
 * <p>
 * 功能介绍：
 */

public class FaBuFriendPressenter extends BasePresenter<IQuanZiBaseView.IFaBuFriendView> {

    /**
     * 作者　　: 李坤
     * 创建时间: 2016/10/31 17:22
     * <p>
     * 方法功能：发布朋友圈	Addfriendquan	CONTENT：发送内容(必填)
     * address:地址
     * friendPhoto:朋友圈图片
     * Showauthority:查看权限
     * 1:公开(所有人可见),
     * 2:秘密(仅自己可见),
     * 3:好友圈(相互关注好友可见),
     * 4:半公开(好友及好友的好友可见),
     * 5:指定给谁看(选中的好友可见)
     */

    public void getHttpData(FaBuFriendData fabudata) {
        HttpCallBack.Buider buider = new HttpCallBack.Buider(this)
                .setHint("发布中");

        HttpCallBack<BaseHttpResponse> callBack = new HttpCallBack<BaseHttpResponse>(buider) {
            @Override
            public void onSuccess(final BaseHttpResponse result) {
                super.onSuccess(result);

                if (result.isSucceed()) {
                    mvpView.showSnackbar(result.getMsg(), SnackbarUtil.Info, true, new Snackbar.Callback() {
                        @Override
                        public void onDismissed(Snackbar snackbar, int event) {
                            super.onDismissed(snackbar, event);
                            mvpView.updataUI(result.getMsg());
                        }
                    });
                } else {
                    mvpView.showErrorSnackbar(result.getMsg());
                }
            }
        };

        HttpRequestParam param = new HttpRequestParam("Addfriendquan");
        param.addParam("content", fabudata.getContent());
        if (fabudata.getPoiData() != null) {
            param.addParam("address", fabudata.getPoiData().getTitle());
        }

        param.addParam("Showauthority", fabudata.getShowQuanXian().getKey());
        param.addParamFile("friendPhoto", fabudata.getFriendPhoto());
        mvpView.addSubscription(HttpRequest.uploadFiles(callBack, param));

    }

}
